import {Trigger} from "solar/w3ts/handles/trigger";
import ForceUtil from "../../solar/util/ForceUtil";
import {MapPlayer} from "../../solar/w3ts/handles/player";

/**
 *
 */
export default class CameraManagerState {
    /**
     * config
     */
    static config = {
        distance: 2000,
    }

    constructor() {
        //base set
        ForceUtil.forUserForce(player => {
            SetCameraFieldForPlayer(player, CAMERA_FIELD_TARGET_DISTANCE, CameraManagerState.config.distance, 0)
            MapPlayer.fromHandle(player).solarData.system_camera = CameraManagerState.config.distance;
        });
        //one case
        let trigger = new Trigger()
        ForceUtil.forUserForce(player => {
            TriggerRegisterPlayerChatEvent(trigger.handle, player, "jt", false)
        });
        trigger.addCondition(Condition(() => {
            return ((StringLength(GetEventPlayerChatString()) == 6) && (SubString(GetEventPlayerChatString(), 0, 2) == "jt"))
        }))
        trigger.addAction(() => {
            let wj = GetTriggerPlayer()
            let mapPlayer = MapPlayer.fromHandle(wj)
            let int = S2I(SubString(GetEventPlayerChatString(), 2, 6))
            if (int < 2000 || int > 3500) {
                DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离超过限制(范围2000-3500)")
                return
            }
            mapPlayer.solarData.system_camera = int;
            DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离设置为" + int)
            SetCameraFieldForPlayer(wj, CAMERA_FIELD_TARGET_DISTANCE, int, 0)
        })
        //one case
        this.initTriggerAdd();
        this.initTriggerSubtract();

    }

    //one case
    initTriggerAdd() {
        let trigger = new Trigger()
        ForceUtil.forUserForce(player => {
            TriggerRegisterPlayerChatEvent(trigger.handle, player, "+", true)
            TriggerRegisterPlayerChatEvent(trigger.handle, player, "++", true)
        });
        trigger.addAction(() => {
            let wj = GetTriggerPlayer()
            let mapPlayer = MapPlayer.fromHandle(wj)
            let int = mapPlayer.solarData.system_camera + 300
            if (int < 2000 || int > 3500) {
                DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离超过限制(范围2000-3500)")
                return
            }
            mapPlayer.solarData.system_camera = int;
            DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离设置为" + int)
            SetCameraFieldForPlayer(wj, CAMERA_FIELD_TARGET_DISTANCE, int, 0)
        })
    }

    //one case
    initTriggerSubtract() {
        let trigger = new Trigger()
        ForceUtil.forUserForce(player => {
            TriggerRegisterPlayerChatEvent(trigger.handle, player, "-", true)
            TriggerRegisterPlayerChatEvent(trigger.handle, player, "--", true)
        });
        trigger.addAction(() => {
            let wj = GetTriggerPlayer()
            let mapPlayer = MapPlayer.fromHandle(wj)
            let int = mapPlayer.solarData.system_camera - 200
            if (int < 2000 || int > 5000) {
                DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离超过限制(范围2000-3500)")
                return
            }
            mapPlayer.solarData.system_camera = int;
            DisplayTimedTextToPlayer(wj, 0, 0, 5.00, "|cffff0000【提示】镜头距离设置为" + int)
            SetCameraFieldForPlayer(wj, CAMERA_FIELD_TARGET_DISTANCE, int, 0)
        })
    }


}
